<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>deprecatedbutton.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
  </script>

  <script src="static/js/doc.js">
  </script>

  <meta charset="utf8">
</head>

<body onload="prettyPrint()">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_ui_deprecatedbutton.js.html">deprecatedbutton.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line2"></a>// you may not use this file except in compliance with the License.
<a name="line3"></a>// You may obtain a copy of the License at
<a name="line4"></a>//
<a name="line5"></a>//     http://www.apache.org/licenses/LICENSE-2.0
<a name="line6"></a>//
<a name="line7"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line8"></a>// distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
<a name="line9"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line10"></a>// See the License for the specific language governing permissions and
<a name="line11"></a>// limitations under the License.
<a name="line12"></a>
<a name="line13"></a>// Copyright 2006 Google Inc. All Rights Reserved.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Deprecated button class; use {@link goog.ui.Button} instead.
<a name="line17"></a> *
<a name="line18"></a> */
<a name="line19"></a>
<a name="line20"></a>goog.provide(&#39;goog.ui.DeprecatedButton&#39;);
<a name="line21"></a>
<a name="line22"></a>goog.require(&#39;goog.dom&#39;);
<a name="line23"></a>goog.require(&#39;goog.events&#39;);
<a name="line24"></a>goog.require(&#39;goog.events.Event&#39;);
<a name="line25"></a>goog.require(&#39;goog.events.EventTarget&#39;);
<a name="line26"></a>
<a name="line27"></a>/**
<a name="line28"></a> * Default implementation of a button. Uses the default browser-style button.
<a name="line29"></a> *
<a name="line30"></a> * @param {string} opt_class Optional class for component.
<a name="line31"></a> *                           Default: &#39;goog-button&#39;.
<a name="line32"></a> * @constructor
<a name="line33"></a> * @extends {goog.events.EventTarget}
<a name="line34"></a> * @deprecated Use {@link goog.ui.Button} instead.
<a name="line35"></a> */
<a name="line36"></a>goog.ui.DeprecatedButton = function(opt_class) {
<a name="line37"></a>  /**
<a name="line38"></a>   * CSS class name for the button.
<a name="line39"></a>   * @type {string}
<a name="line40"></a>   * @private
<a name="line41"></a>   */
<a name="line42"></a>  this.class_ = opt_class ? opt_class : &#39;goog-button&#39;;
<a name="line43"></a>
<a name="line44"></a>  /**
<a name="line45"></a>   * Unique ID for the instance of this component.
<a name="line46"></a>   * @type {string}
<a name="line47"></a>   * @private
<a name="line48"></a>   */
<a name="line49"></a>  this.id_ = this.getNextUniqueId_();
<a name="line50"></a>};
<a name="line51"></a>goog.inherits(goog.ui.DeprecatedButton, goog.events.EventTarget);
<a name="line52"></a>
<a name="line53"></a>
<a name="line54"></a>/**
<a name="line55"></a> * Prefix for all ID&#39;s of this component.
<a name="line56"></a> * @type {string}
<a name="line57"></a> * @private
<a name="line58"></a> */
<a name="line59"></a>goog.ui.DeprecatedButton.BASE_ID_ = &#39;goog.ui.DeprecatedButton.&#39;;
<a name="line60"></a>
<a name="line61"></a>
<a name="line62"></a>/**
<a name="line63"></a> * Next unique instance ID for this component.
<a name="line64"></a> * @type {number}
<a name="line65"></a> * @private
<a name="line66"></a> */
<a name="line67"></a>goog.ui.DeprecatedButton.nextId_ = 0;
<a name="line68"></a>
<a name="line69"></a>
<a name="line70"></a>/**
<a name="line71"></a> * Gets the next unique ID for the component.
<a name="line72"></a> * @return {string} The next unique ID for the component.
<a name="line73"></a> */
<a name="line74"></a>goog.ui.DeprecatedButton.getNextUniqueId = function() {
<a name="line75"></a>  return goog.ui.DeprecatedButton.BASE_ID_ + goog.ui.DeprecatedButton.nextId_++;
<a name="line76"></a>};
<a name="line77"></a>
<a name="line78"></a>
<a name="line79"></a>/**
<a name="line80"></a> * Gets the next unique ID for the component. This method is used in the
<a name="line81"></a> * constructor to generate the unique ID for the component.
<a name="line82"></a> *
<a name="line83"></a> * NOTE: This method is placed on the prototype so that classes that inherit
<a name="line84"></a> * this class can override this method and have the ID automatically set by
<a name="line85"></a> * calling the parent class&#39;s constructor.
<a name="line86"></a> *
<a name="line87"></a> * @return {string} The next unique ID for the component.
<a name="line88"></a> * @private
<a name="line89"></a> */
<a name="line90"></a>goog.ui.DeprecatedButton.prototype.getNextUniqueId_ = function() {
<a name="line91"></a>  return goog.ui.DeprecatedButton.getNextUniqueId();
<a name="line92"></a>};
<a name="line93"></a>
<a name="line94"></a>
<a name="line95"></a>/**
<a name="line96"></a>* Events fired by the Component.
<a name="line97"></a>* @enum {string}
<a name="line98"></a>*/
<a name="line99"></a>goog.ui.DeprecatedButton.EventType = {
<a name="line100"></a>  /**
<a name="line101"></a>   * Fired by the Component when it is activated.
<a name="line102"></a>   */
<a name="line103"></a>  ACTIVATE: &#39;activate&#39;,
<a name="line104"></a>
<a name="line105"></a>  /**
<a name="line106"></a>   * Fired by the Component when it is enabled/disabled.
<a name="line107"></a>   */
<a name="line108"></a>  ENABLE: &#39;enable&#39;
<a name="line109"></a>};
<a name="line110"></a>
<a name="line111"></a>
<a name="line112"></a>/**
<a name="line113"></a> * Whether componet is enabled.
<a name="line114"></a> * @type {boolean}
<a name="line115"></a> * @private
<a name="line116"></a> */
<a name="line117"></a>goog.ui.DeprecatedButton.prototype.enabled_ = true;
<a name="line118"></a>
<a name="line119"></a>
<a name="line120"></a>/**
<a name="line121"></a> * Whether componet is rendered.
<a name="line122"></a> * @type {boolean}
<a name="line123"></a> * @private
<a name="line124"></a> */
<a name="line125"></a>goog.ui.DeprecatedButton.prototype.rendered_ = false;
<a name="line126"></a>
<a name="line127"></a>
<a name="line128"></a>/**
<a name="line129"></a> * HTML caption displayed in the component.
<a name="line130"></a> * @type {string?}
<a name="line131"></a> * @private
<a name="line132"></a> */
<a name="line133"></a>goog.ui.DeprecatedButton.prototype.caption_ = null;
<a name="line134"></a>
<a name="line135"></a>
<a name="line136"></a>/**
<a name="line137"></a> * Tooltip for the component.
<a name="line138"></a> * @type {string?}
<a name="line139"></a> * @private
<a name="line140"></a> */
<a name="line141"></a>goog.ui.DeprecatedButton.prototype.tooltip_ = null;
<a name="line142"></a>
<a name="line143"></a>
<a name="line144"></a>/**
<a name="line145"></a> * Value associated with the component.
<a name="line146"></a> * @type {Object?}
<a name="line147"></a> * @private
<a name="line148"></a> */
<a name="line149"></a>goog.ui.DeprecatedButton.prototype.value_ = null;
<a name="line150"></a>
<a name="line151"></a>
<a name="line152"></a>/**
<a name="line153"></a> * Main element for the component.
<a name="line154"></a> * @type {Element?}
<a name="line155"></a> * @private
<a name="line156"></a> */
<a name="line157"></a>goog.ui.DeprecatedButton.prototype.element_ = null;
<a name="line158"></a>
<a name="line159"></a>
<a name="line160"></a>/**
<a name="line161"></a> * Gets the caption for the component.
<a name="line162"></a> * @return {string?} The caption.
<a name="line163"></a> */
<a name="line164"></a>goog.ui.DeprecatedButton.prototype.getCaption = function() {
<a name="line165"></a>  return this.caption_;
<a name="line166"></a>};
<a name="line167"></a>
<a name="line168"></a>
<a name="line169"></a>/**
<a name="line170"></a> * Sets the caption for the component.
<a name="line171"></a> * @param {string} caption The caption.
<a name="line172"></a> */
<a name="line173"></a>goog.ui.DeprecatedButton.prototype.setCaption = function(caption) {
<a name="line174"></a>  this.caption_ = caption;
<a name="line175"></a>  if (this.isRendered()) {
<a name="line176"></a>    var element = this.getElement();
<a name="line177"></a>
<a name="line178"></a>    element.value = caption;
<a name="line179"></a>    goog.dom.setTextContent(element, caption);
<a name="line180"></a>  }
<a name="line181"></a>};
<a name="line182"></a>
<a name="line183"></a>
<a name="line184"></a>/**
<a name="line185"></a> * Gets the tooltip for the component.
<a name="line186"></a> * @return {string?} The tooltip.
<a name="line187"></a> */
<a name="line188"></a>goog.ui.DeprecatedButton.prototype.getTooltip = function() {
<a name="line189"></a>  return this.tooltip_;
<a name="line190"></a>};
<a name="line191"></a>
<a name="line192"></a>
<a name="line193"></a>/**
<a name="line194"></a> * Sets the tooltip for the component.
<a name="line195"></a> * @param {string} tooltip The tooltip.
<a name="line196"></a> */
<a name="line197"></a>goog.ui.DeprecatedButton.prototype.setTooltip = function(tooltip) {
<a name="line198"></a>  this.tooltip_ = tooltip;
<a name="line199"></a>  if (this.isRendered()) {
<a name="line200"></a>    this.getElement().title = tooltip;
<a name="line201"></a>  }
<a name="line202"></a>};
<a name="line203"></a>
<a name="line204"></a>
<a name="line205"></a>/**
<a name="line206"></a> * Gets the value for the component.
<a name="line207"></a> * @return {Object?} The value.
<a name="line208"></a> */
<a name="line209"></a>goog.ui.DeprecatedButton.prototype.getValue = function() {
<a name="line210"></a>  return this.value_;
<a name="line211"></a>};
<a name="line212"></a>
<a name="line213"></a>
<a name="line214"></a>/**
<a name="line215"></a> * Sets the value for the component.
<a name="line216"></a> * @param {Object} value The value.
<a name="line217"></a> */
<a name="line218"></a>goog.ui.DeprecatedButton.prototype.setValue = function(value) {
<a name="line219"></a>  this.value_ = value;
<a name="line220"></a>};
<a name="line221"></a>
<a name="line222"></a>
<a name="line223"></a>/**
<a name="line224"></a> * Gets the enabled status for the component.
<a name="line225"></a> * @return {boolean} The enabled status.
<a name="line226"></a> */
<a name="line227"></a>goog.ui.DeprecatedButton.prototype.getEnabled = function() {
<a name="line228"></a>  return this.enabled_;
<a name="line229"></a>};
<a name="line230"></a>
<a name="line231"></a>
<a name="line232"></a>/**
<a name="line233"></a> * Sets the enabled status for the component.
<a name="line234"></a> * @param {boolean} enable The enabled status.
<a name="line235"></a> */
<a name="line236"></a>goog.ui.DeprecatedButton.prototype.setEnabled = function(enable) {
<a name="line237"></a>  // Fire event to see if can be enabled.
<a name="line238"></a>  if (this.getEnabled() != enable &amp;&amp;
<a name="line239"></a>      this.dispatchEvent(goog.ui.DeprecatedButton.EventType.ENABLE)) {
<a name="line240"></a>    if (this.isRendered()) {
<a name="line241"></a>      this.element_.disabled = !enable;
<a name="line242"></a>    }
<a name="line243"></a>    this.enabled_ = enable;
<a name="line244"></a>  }
<a name="line245"></a>};
<a name="line246"></a>
<a name="line247"></a>
<a name="line248"></a>/**
<a name="line249"></a> * Gets the CSS className for the component.
<a name="line250"></a> * @return {string} The class name.
<a name="line251"></a> */
<a name="line252"></a>goog.ui.DeprecatedButton.prototype.getClass = function() {
<a name="line253"></a>  return this.class_;
<a name="line254"></a>};
<a name="line255"></a>
<a name="line256"></a>
<a name="line257"></a>/**
<a name="line258"></a> * Gets the element representing the UI component.
<a name="line259"></a> * @return {Element?} Element representing component if any. Otherwise, null.
<a name="line260"></a> */
<a name="line261"></a>goog.ui.DeprecatedButton.prototype.getElement = function() {
<a name="line262"></a>  return this.element_;
<a name="line263"></a>};
<a name="line264"></a>
<a name="line265"></a>
<a name="line266"></a>/**
<a name="line267"></a> * Gets the unique ID for the instance of this component.
<a name="line268"></a> * @return {string} Unique element id.
<a name="line269"></a> */
<a name="line270"></a>goog.ui.DeprecatedButton.prototype.getId = function() {
<a name="line271"></a>  return this.id_;
<a name="line272"></a>};
<a name="line273"></a>
<a name="line274"></a>
<a name="line275"></a>/**
<a name="line276"></a> * Determines whether the component has been rendered.
<a name="line277"></a> * @return {boolean} TRUE iff rendered. Otherwise, FALSE.
<a name="line278"></a> */
<a name="line279"></a>goog.ui.DeprecatedButton.prototype.isRendered = function() {
<a name="line280"></a>  return this.rendered_;
<a name="line281"></a>};
<a name="line282"></a>
<a name="line283"></a>
<a name="line284"></a>/**
<a name="line285"></a> * Renders the component. Throws an Error if the component is already rendered.
<a name="line286"></a> * @param {Element} opt_element Element to render the compponent into.
<a name="line287"></a> *                              If omitted, then the componenet is appended to
<a name="line288"></a> *                              the document.
<a name="line289"></a> */
<a name="line290"></a>goog.ui.DeprecatedButton.prototype.render = function(opt_element) {
<a name="line291"></a>  if (this.isRendered()) {
<a name="line292"></a>    throw Error(&#39;Compenent already rendered&#39;);
<a name="line293"></a>  }
<a name="line294"></a>
<a name="line295"></a>  // Get the DOM helper.
<a name="line296"></a>  var domHelper = goog.dom.getDomHelper(opt_element);
<a name="line297"></a>
<a name="line298"></a>  // Create element.
<a name="line299"></a>  var element = domHelper.createDom(&#39;button&#39;, {
<a name="line300"></a>    value: this.caption_,
<a name="line301"></a>    title: this.tooltip_,
<a name="line302"></a>    disabled: !this.enabled_,
<a name="line303"></a>    className: this.class_
<a name="line304"></a>  });
<a name="line305"></a>
<a name="line306"></a>  // set the text shown in the button
<a name="line307"></a>  goog.dom.setTextContent(element, this.caption_);
<a name="line308"></a>
<a name="line309"></a>  // Append to parent.
<a name="line310"></a>  var parentElement = opt_element || domHelper.getDocument().body;
<a name="line311"></a>  domHelper.appendChild(parentElement, element);
<a name="line312"></a>
<a name="line313"></a>  // Setup event handlers.
<a name="line314"></a>  goog.events.listen(element, goog.events.EventType.CLICK,
<a name="line315"></a>      this.onClick_, true, this);
<a name="line316"></a>
<a name="line317"></a>  this.element_ = element;
<a name="line318"></a>  this.rendered_ = true;
<a name="line319"></a>};
<a name="line320"></a>
<a name="line321"></a>
<a name="line322"></a>/**
<a name="line323"></a> * Decorates the element for the UI component.
<a name="line324"></a> * @param {Element} element Element to decorate.
<a name="line325"></a> */
<a name="line326"></a>goog.ui.DeprecatedButton.prototype.decorate = function(element) {
<a name="line327"></a>  if (this.isRendered()) {
<a name="line328"></a>    throw Error(&#39;Component already rendered&#39;);
<a name="line329"></a>  } else if (element &amp;&amp; (element.tagName == &#39;BUTTON&#39; ||
<a name="line330"></a>      (element.tagName == &#39;INPUT&#39; &amp;&amp; (element.type == &#39;BUTTON&#39; ||
<a name="line331"></a>          element.type == &#39;SUBMIT&#39; || element.type == &#39;RESET&#39;)))) {
<a name="line332"></a>    // Setup properties.
<a name="line333"></a>    this.element_ = element;
<a name="line334"></a>    this.setCaption(element.value);
<a name="line335"></a>    this.setTooltip(element.title);
<a name="line336"></a>    this.class_ = element.className;
<a name="line337"></a>    // Setup event handlers.
<a name="line338"></a>    goog.events.listen(element, goog.events.EventType.CLICK,
<a name="line339"></a>        this.onClick_, true, this);
<a name="line340"></a>    this.rendered_ = true;
<a name="line341"></a>  } else {
<a name="line342"></a>    throw Error(&#39;Invalid element to decorate&#39;);
<a name="line343"></a>  }
<a name="line344"></a>};
<a name="line345"></a>
<a name="line346"></a>
<a name="line347"></a>/**
<a name="line348"></a> * Handles the DOM click event. Dispatches the button ACTIVATE Event.
<a name="line349"></a> * @param {Object} e The event.
<a name="line350"></a> * @private
<a name="line351"></a> */
<a name="line352"></a>goog.ui.DeprecatedButton.prototype.onClick_ = function(e) {
<a name="line353"></a>  if (this.getEnabled()) {
<a name="line354"></a>    this.dispatchEvent(goog.ui.DeprecatedButton.EventType.ACTIVATE);
<a name="line355"></a>  }
<a name="line356"></a>};
<a name="line357"></a>
<a name="line358"></a>
<a name="line359"></a>/** @inheritDoc */
<a name="line360"></a>goog.ui.DeprecatedButton.prototype.disposeInternal = function() {
<a name="line361"></a>  goog.ui.DeprecatedButton.superClass_.disposeInternal.call(this);
<a name="line362"></a>
<a name="line363"></a>  // Cleanup DOM.
<a name="line364"></a>  var element = this.element_;
<a name="line365"></a>  if (element) {
<a name="line366"></a>    // Cleanup DOM events.
<a name="line367"></a>    goog.events.unlisten(element, goog.events.EventType.CLICK,
<a name="line368"></a>        this.onClick_, true, this);
<a name="line369"></a>
<a name="line370"></a>    // Remove node.
<a name="line371"></a>    var domHelper = goog.dom.getDomHelper(element);
<a name="line372"></a>    domHelper.removeNode(element);
<a name="line373"></a>    this.element_ = null;
<a name="line374"></a>  }
<a name="line375"></a>
<a name="line376"></a>  // Cleanup properties.
<a name="line377"></a>  delete this.value_;
<a name="line378"></a>};
</pre>


</body>
</html>
